from django.core.serializers import get_serializer
from django.shortcuts import render
from django_redis import get_redis_connection
from rest_framework import status, mixins
from rest_framework.decorators import action
from rest_framework.generics import CreateAPIView, RetrieveAPIView, UpdateAPIView, GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet
from rest_framework_jwt.views import ObtainJSONWebToken

from users.serializers import InfoSerializer
from . import serializers
from .models import User, Info


# from . import constants
# from goods.models import SKU
# from carts.utils import merge_cart_cookie_to_redis

# Create your views here.


# url(r'^users/$', views.UserView.as_view()),
class UserView(CreateAPIView):
    """
    用户注册
    传入参数：
        username, password, password2, sms_code, mobile, allow
    """
    serializer_class = serializers.CreateUserSerializer


class UserAuthorizeView(ObtainJSONWebToken):
    """用户登录认证视图"""

    def post(self, request, *args, **kwargs):
        response = super().post(request, *args, **kwargs)

        serializer = self.get_serializer(data=request.data)
        if serializer.is_valid():
            user = serializer.validated_data['user']

        return response

class InfoView(RetrieveAPIView):

    serializer_class = InfoSerializer
    queryset = Info.objects.all()
    # permission_classes = [IsAuthenticated]



